<?php
/**
 * Core_Acl_Controller_Plugin
 * 
 * @author naspeh
 * @version $Id: Plugin.php 661 2008-06-16 10:38:02Z naspeh $
 */
class Core_Acl_Controller_Plugin extends Zend_Controller_Plugin_Abstract 
{
    /**
     * Запускается до цикла диспетчеризации
     *
     * @param Zend_Controller_Request_Abstract $request
     */
    public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
    {
        $label = implode('/', array($request->getModuleName(), $request->getControllerName(), $request->getActionName()));
        if (false !== ($resource = Core_Table_Actions::fetchByUrl($label))) {
            $resource = new Core_Acl_Resource_Action($resource);
            $acl = Core_Acl::getRegisrty(); 
            $acl->active($resource);
            if (!$acl->isAllowed(Core_Auth::get('id'), $resource)) {
                throw new Core_Exception('accessDenied#', 403);
            }
        }
    }    
}